{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

{{#isAccessible ADMIN}}
  <div id="alert-actions-button" class="pull-left">
    {{view App.MainAlertDefinitionActionsView controllerBinding="App.router.mainAlertDefinitionActionsController"}}
  </div>
{{/isAccessible}}

<div id="alert-groups-filter" class="pull-left advanced-header-table groups-filter">
{{#if App.router.clusterController.isAlertsLoaded}}
  {{view view.alertGroupFilterView}}
{{/if}}
</div>

<div id="alerts">
  <div class="box-header row">
  </div>
  <table class="table advanced-header-table table-bordered table-striped alerts-table" id="alert-definitions-table">
    <thead>
    {{#view view.sortView classNames="label-row" contentBinding="view.filteredContent"}}
      {{view view.parentView.nameSort class="first name-sorting"}}
      {{view view.parentView.statusSort class="status-sorting"}}
      {{view view.parentView.serviceSort class="service-sorting"}}
      {{view view.parentView.lastTriggeredSort class="last-triggred-sorting"}}
      {{view view.parentView.enabledSort class="enabled-sorting"}}
    {{/view}}
    <tr class="filter-row">
      <th class="first">{{view view.nameFilterView class="name-filter"}}</th>
      <th>{{view view.stateFilterView class="status-filter"}}</th>
      <th>{{view view.serviceFilterView class="service-filter"}}</th>
      <th>{{view view.triggeredFilterView class="last-triggered-filter"}}</th>
      <th>{{view view.enabledFilterView class="enabled-filter"}}</th>
    </tr>
    </thead>
    <tbody>
    {{#if App.router.clusterController.isAlertsLoaded}}
      {{#if view.pageContent}}
        {{#each alertDefinition in view.pageContent}}
          <tr>
            <td class="first">
              <span {{bindAttr title="alertDefinition.type"}} {{bindAttr class=":type-icon  alertDefinition.typeIconClass"}}></span>
              <a href="#" {{action "gotoAlertDetails" alertDefinition}}>{{alertDefinition.label}}</a>
            </td>
            <td>{{{alertDefinition.status}}}</td>
            <td>{{alertDefinition.serviceDisplayName}}</td>
            <td>
              <time class="timeago" {{bindAttr data-original-title="alertDefinition.lastTriggeredFormatted"}}>{{alertDefinition.lastTriggeredAgoFormatted}}</time>
            </td>
            <td class="last toggle-state-button">
              {{#if alertDefinition.enabled}}
                {{#isAccessible ADMIN}}
                  <a href="#" {{action "toggleState" alertDefinition target="controller"}} {{bindAttr class="alertDefinition.enabled:alert-definition-enable:alert-definition-disable"}}>
                  <span class="enable-disable-button" {{bindAttr data-original-title="view.enabledTooltip"}}>
                    {{view.enabledDisplay}}
                  </span>
                  </a>
                {{/isAccessible}}
                {{#isAccessible NON_ADMIN}}
                  <span {{bindAttr class="alertDefinition.enabled:alert-definition-enable:alert-definition-disable"}}>
                    {{t alerts.table.state.enabled}}
                  </span>
                {{/isAccessible}}
              {{else}}
                {{#isAccessible ADMIN}}
                  <a href="#" {{action "toggleState" alertDefinition target="controller"}} {{bindAttr class="alertDefinition.enabled:alert-definition-enable:alert-definition-disable"}}>
                  <span class="enable-disable-button" {{bindAttr data-original-title="view.disabledTooltip"}}>
                    {{view.disabledDisplay}}
                  </span>
                  </a>
                {{/isAccessible}}
                {{#isAccessible NON_ADMIN}}
                  <span {{bindAttr class="alertDefinition.enabled:alert-definition-enable:alert-definition-disable"}}>
                    {{t alerts.table.state.disabled}}
                  </span>
                {{/isAccessible}}
              {{/if}}
            </td>
          </tr>
        {{/each}}
      {{else}}
        <tr>
          <td class="first"></td>
          <td colspan="4">
            {{t alerts.table.noAlerts}}
          </td>
        </tr>
      {{/if}}
    {{else}}
      <tr>
        <td class="first"></td>
        <td colspan="2">
          <div class="spinner"></div>
        </td>
      </tr>
    {{/if}}
    </tbody>
  </table>

  <div class="page-bar">
    <div class="filtered-info span4">
      <label>{{view.filteredContentInfo}} - <a {{action clearFilters target="view"}}
              href="#">{{t tableView.filters.clearAllFilters}}</a></label>
    </div>
    <div class="selected-hosts-info span4">
    </div>
    <div class="items-on-page">
      <label>{{t common.show}}: {{view view.rowsPerPageSelectView selectionBinding="view.displayLength"}}</label>
    </div>
    <div class="info">{{view.paginationInfo}}</div>
    <div class="paging_two_button">
      <a {{bindAttr class="view.paginationLeftClass"}}{{action previousPage target="view"}}><i
              class="icon-arrow-left"></i></a>
      <a {{bindAttr class="view.paginationRightClass"}}{{action nextPage target="view"}}><i
              class="icon-arrow-right"></i></a>
    </div>
  </div>
</div>
